package control.panel
{
	import events.TableEvent;
	
	import flash.events.MouseEvent;
	
	import model.room.TableModel;
	
	import view.components.AnimateShow;
	import view.components.InfoBar;
	import view.panel.RoomInfoPanel;
	
	import global.GameState;
	
	public class RoomInfoPanelControl extends PanelControl
	{
		private var tableModel:TableModel;
		private var animateShow:AnimateShow;
		private var infoBar:InfoBar;
		
		public function RoomInfoPanelControl(tableModel:TableModel)
		{
			this.tableModel = tableModel;
			initInfoBar();
			initPanel();
			initListeners();
			initAnimateShow();
		}
		
		private function initInfoBar():void
		{
			infoBar = new InfoBar();
			infoBar.x = 5;
			infoBar.y = 5;
			
			
			infoBar.addEventListener(MouseEvent.MOUSE_OVER,onInfoBarOver);
			infoBar.addEventListener(MouseEvent.MOUSE_OUT,onInfoBarOut);
		}
		
		private function onInfoBarOver(event:MouseEvent):void
		{
			animateShow.start();
		}
		
		private function onInfoBarOut(event:MouseEvent):void
		{
			animateShow.back();	
		}	
		
		private function initAnimateShow():void
		{
			animateShow = new AnimateShow();
			animateShow.duration = 1;
			animateShow.setDirection(AnimateShow.DIRECTION_TOP);
			animateShow.setTarget(_view.roomInfoPanel);
			animateShow.x = infoBar.x + 6;
			animateShow.y = infoBar.y + infoBar.height - 15;
			_view.tableLayer.addSitBut(animateShow);
			_view.tableLayer.addSitBut(infoBar);
		}
		
		private function initPanel():void
		{
			_view.roomInfoPanel = new RoomInfoPanel(this);
			_view.tableLayer.addChild(_view.roomInfoPanel);	
		}
		
		
		private function initListeners():void
		{
			tableModel.addEventListener(TableEvent.ROOM_INFO,onRoomInfo);
		}
		
		private function onRoomInfo(event:TableEvent):void
		{
			_view.roomInfoPanel.updateInfo(event.roomData);
			infoBar.update("游戏房间名称是：" + event.roomData.roomName);
			GameState.gameRoomFee = event.roomData.fee;
		}
		
		
	}
}